home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / lzw4c13.zip / DIR_IO.C < prev    next >
Text File  |  1993-08-28  |  2KB  |  104 lines

  1. /*
  2. **  DIR_IO.C
  3. **
  4. **  Compile with Microsoft C, Borland Turbo C, or MIX Power C.  You may
  5. **  need to modify the following code for your specfic compiler. Some
  6. **  older versions of Microsoft C do not support directory I/O.
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <dos.h>
  11. #include <string.h>
  12.  
  13. #ifndef FALSE
  14. #define FALSE 0
  15. #endif
  16.  
  17. #ifndef TRUE
  18. #define TRUE !FALSE
  19. #endif
  20.  
  21. /*** define compiler specfic includes ***/
  22.  
  23. #ifdef __POWERC
  24. /* MIX Power C compiler */
  25. #define TURBO_OR_POWERC
  26. #define SUPPORTED_COMPILER
  27. #include <direct.h>
  28. #endif
  29.  
  30. #ifdef __TURBOC__
  31. /* Borland Turbo C compiler */
  32. #define TURBO_OR_POWERC
  33. #define SUPPORTED_COMPILER
  34. #include <dir.h>
  35. #endif
  36.  
  37. #ifdef _MSC_VER
  38. /* Microsoft C compiler */
  39. #define SUPPORTED_COMPILER
  40. static struct _find_t DirStruct;
  41. #endif
  42.  
  43. #ifdef TURBO_OR_POWERC
  44. static char DTAbuffer[256];
  45. static struct ffblk DirStruct;
  46. #endif
  47.  
  48. /*** FindFirst() and FindNext() functions ***/
  49.  
  50. int FindFirst(char *FileSpec,char *Buffer)
  51. {
  52. #ifndef SUPPORTED_COMPILER
  53.  /* compiler doesn't support directory I/O ! */
  54.  strncpy(Buffer,FileSpec,13);
  55. #endif
  56.  
  57. #ifdef _MSC_VER
  58.  if(_dos_findfirst(FileSpec,_A_NORMAL,&DirStruct)==0)
  59.    {
  60.     strncpy(Buffer,DirStruct.name,13);
  61.     return(TRUE);
  62.    }
  63.  return(FALSE);
  64. #endif
  65.  
  66. #ifdef TURBO_OR_POWERC
  67.  setdta(DTAbuffer);
  68.  if( findfirst(FileSpec,&DirStruct,0)==0)
  69.    {
  70.     strncpy(Buffer,DirStruct.ff_name,13);
  71.     return(TRUE);
  72.    }
  73.  return(FALSE);
  74. #endif
  75. }
  76.  
  77. int FindNext(char *Buffer)
  78. {int Result;
  79.  
  80. #ifndef SUPPORTED_COMPILER
  81.  /* compiler doesn't support directory I/O ! */
  82.  return(FALSE);
  83. #endif
  84.  
  85. #ifdef _MSC_VER
  86. Result = _dos_findnext(&DirStruct);
  87. if(Result==0)
  88.    {
  89.     strncpy(Buffer,DirStruct.name,13);
  90.     return(TRUE);
  91.    }
  92.  return(FALSE);
  93. #endif
  94.  
  95. #ifdef TURBO_OR_POWERC
  96.  if( findnext(&DirStruct)==0 )
  97.    {
  98.     strncpy(Buffer,DirStruct.ff_name,13);
  99.     return(TRUE);
  100.    }
  101.  return(FALSE);
  102. #endif
  103. }
  104.